#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>


#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))


int querycap(int fd)
{
    struct v4l2_capability vcap = {0};

    if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0) {
        printf("query cap error!\n");
        return -1;
    }

    printf("driver: %s\n", vcap.driver);
    printf("card: %s\n",   vcap.card);
    printf("bus_info: %s\n", vcap.bus_info);
    printf("version: %08X\n", vcap.version);
    printf("capabilities: %08X\n", vcap.capabilities);
    printf("device_caps: %08X\n", vcap.device_caps);

    for (int i = 0; i < ARRAY_SIZE(vcap.reserved); i++) {
        printf("reserved[%d]: %08X\n", i, vcap.reserved[i]);
    }

    return 0;
}


int main(int argc, char *argv[])
{
    if (argc < 2) {
        printf("help\n");
        return -1;
    }

    int fd = open(argv[1], O_RDWR);
    if (fd < 0) {
        printf("can't open: %s\n", argv[1]);
        return -1;
    }

    printf("device: %s\n", argv[1]);
    printf("----------------\n");
    querycap(fd);

    return 0;
}
